//
//  PPMediator+PPCache.m
//  PPMediator_Example
//
//  Created by ppss on 2021/6/18.
//  Copyright © 2021 ppss. All rights reserved.
//

#import "PPMediator+PPCache.h"

@implementation PPMediator (PPCache)
- (BOOL)PPMediator_ContainsObjectForKey:(NSString *)key{
    
    NSMutableDictionary *paramsToSend = [[NSMutableDictionary alloc] init];
  
    paramsToSend[@"key"] = key;
    
    return [self performTarget:@"PPCacheManager"
                 action:@"containsObjectWithParams"
                 params:paramsToSend
      shouldCacheTarget:NO];
}

//存储数据
- (void)PPMediator_SetCacheWithData:(id)data Key:(NSString *)key{
    
    NSMutableDictionary *paramsToSend = [[NSMutableDictionary alloc] init];
  
    paramsToSend[@"key"] = key;
    
    paramsToSend[@"data"] = data;

    [self performTarget:@"PPCacheManager"
                 action:@"setCacheWithParams"
                 params:paramsToSend
      shouldCacheTarget:NO];
}

//获取数据
- (id)PPMediator_GetCacheForKey:(NSString *)key{
    
    NSMutableDictionary *paramsToSend = [[NSMutableDictionary alloc] init];
  
    paramsToSend[@"key"] = key;
    
    return [self performTarget:@"PPCacheManager"
                 action:@"getCacheWithParams"
                 params:paramsToSend
      shouldCacheTarget:NO];
}

//移除数据
- (void)PPMediator_RemoveCacheForKey:(NSString *)key{
    NSMutableDictionary *paramsToSend = [[NSMutableDictionary alloc] init];
  
    paramsToSend[@"key"] = key;
    
    [self performTarget:@"PPCacheManager"
                 action:@"removeCacheWithParams"
                 params:paramsToSend
      shouldCacheTarget:NO];
}

//移除所有数据
- (void)PPMediator_RemoveAllCache{
    [self performTarget:@"PPCacheManager"
                 action:@"removeAllCache"
                 params:@{}
      shouldCacheTarget:NO];
}

//获取缓存数据大小
- (NSInteger)PPMediator_GetAllCacheSize{
    
    return (NSInteger)[self performTarget:@"PPCacheManager"
                 action:@"getAllCacheSize"
                        params:@{}
      shouldCacheTarget:NO];
}

#pragma mark - 内存持久化
//存储数据
- (void)PPMediator_SetMemoryCacheWithData:(id)data Key:(NSString *)key{
    
    NSMutableDictionary *paramsToSend = [[NSMutableDictionary alloc] init];
  
    paramsToSend[@"key"] = key;
    
    paramsToSend[@"data"] = data;

    [self performTarget:@"PPCacheManager"
                 action:@"setMemoryCacheWithParams"
                 params:paramsToSend
      shouldCacheTarget:NO];
}

//获取数据
- (id)PPMediator_GetMemoryCacheForKey:(NSString *)key{
    
    NSMutableDictionary *paramsToSend = [[NSMutableDictionary alloc] init];
  
    paramsToSend[@"key"] = key;
    
    return [self performTarget:@"PPCacheManager"
                 action:@"getMemoryCacheWithParams"
                 params:paramsToSend
      shouldCacheTarget:NO];
}
@end
